<?php
/**
 * @author ANHTAM
 */
// Require module for controller
require_once(LIB_DAO_DIR . "/MIntro.class.php");

class MIntro_Controller extends ControllerAdmin {
	/**
     * - Constructor
     */
    public function __construct() {
    	parent::__construct();
    	$this->flagMIntro = true;
    	
    	$this->dataUser = Session::Get("MUSER");
        if (is_array($this->dataUser) && !empty($this->dataUser)) {
        	$this->loginFlag = true;
        }
    }
    
    /**
     * actionIndex
     * - page index of controller
     */
	public function actionIndex() {
    	
    	// Process init
        $objView = new ViewAdmin();
        $this->tpl_title = 'Access Admin';
        
        // Process view
        $objView->assignobj($this);
        $objView->display();
    }

	/**
     * actionEdit
     * - page edit of controller
     */
    public function actionEdit() {
    	
    	// Process init
        $objView = new ViewAdmin();
        $this->tpl_title = 'Đổi nội dung';
        $this->arrUser = array();
        $this->dialog = false;
        $this->tpl_title_list = 'Thay đổi bài giới thiệu !';
        $this->tpl_button = "Sửa";
        
    	if (!$this->loginFlag) {
        	FunctionCommon::sendRedirect();
        }
        
        $MIntro = new MIntro();
        $arrId = FunctionCommon::getGet(array('id'));
        $this->id = $arrId['id'];

        if ($this->id != '') {
        	$this->dataPost = $MIntro->getByPrimaryKey($this->id);
        } else {
        	$this->dataPost = FunctionCommon::getPost(array('itemID', 'mode', 'type', 'tomtat', 'tomtat_en', 'noidung', 'noidung_en'));
        	if ($this->dataPost['mode'] != '') {
	        	$MIntro->setAttribute('tomtat', $this->dataPost['tomtat']);
	        	$MIntro->setAttribute('tomtat_en', $this->dataPost['tomtat_en']);
	        	$MIntro->setAttribute('noidung', $this->dataPost['noidung']);
	        	$MIntro->setAttribute('noidung_en', $this->dataPost['noidung_en']);
	        	$MIntro->update(array('id' => $this->dataPost['itemID']));
	        	$this->dialog = true;
        	}
        }

        // Process view
        $objView->assignobj($this);
        $objView->display();
    }
}
?>

